package
{
	import com.utils.GetMovieClip;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class ArrowBtn extends Sprite
	{
		private var upArrow:MovieClip;
		private var downArrow:MovieClip;
		
		private var timer:Timer;
		private var fun:Function;
		public function ArrowBtn()
		{
			upArrow=GetMovieClip.getMovieClip("Arrow");
			downArrow=GetMovieClip.getMovieClip("Arrow");
			downArrow.y = 480;
			upArrow.rotation=-180;
			upArrow.stop();
			downArrow.stop();
			addChild(upArrow);
			addChild(downArrow);
			
			addEvent();
		}
		private function addEvent():void{
			upArrow.addEventListener(MouseEvent.MOUSE_DOWN, onUpClick);
			downArrow.addEventListener(MouseEvent.MOUSE_DOWN, onDownClick);
			upArrow.addEventListener(MouseEvent.ROLL_OUT, onOut);
			downArrow.addEventListener(MouseEvent.ROLL_OUT, onOut);
			upArrow.addEventListener(MouseEvent.ROLL_OVER, onOver);
			downArrow.addEventListener(MouseEvent.ROLL_OVER, onOver);
		}
		
		private function onUpClick(e:MouseEvent):void 
		{
			//sendUpDispatch();
		}
		
		private function onDownClick(e:MouseEvent):void 
		{
			//sendDownDispatch();
		}
	
		private function onOut(e:MouseEvent):void{ 
			//var mc:MovieClip=e.currentTarget as MovieClip;
			//mc.gotoAndStop(1);
			stopMove();
		}
		private function onOver(e:MouseEvent):void{
			//var mc:MovieClip=e.currentTarget as MovieClip;
			//mc.gotoAndStop(2);
			if(e.currentTarget==upArrow){
				fun=sendUpDispatch;
			}else if(e.currentTarget==downArrow){
				fun=sendDownDispatch;
			}
			moveOverMenu(fun);
			
		}
		private function delEvent():void{
			upArrow.removeEventListener(MouseEvent.MOUSE_DOWN, onUpClick);
			downArrow.removeEventListener(MouseEvent.MOUSE_DOWN, onDownClick);
			upArrow.removeEventListener(MouseEvent.ROLL_OUT, onOut);
			downArrow.removeEventListener(MouseEvent.ROLL_OUT, onOut);
			upArrow.removeEventListener(MouseEvent.ROLL_OVER, onOver);
			downArrow.removeEventListener(MouseEvent.ROLL_OVER, onOver);
		}
		private function moveOverMenu(fun:Function):void{
			timer=new Timer(200,0);
			timer.start();
			timer.addEventListener(TimerEvent.TIMER,fun);
		}
		private function stopMove(e:MouseEvent=null):void{
			if(timer==null)return;
			timer.stop();
			timer.removeEventListener(TimerEvent.TIMER,fun);
			timer=null;
		}
		private function sendUpDispatch(e:TimerEvent=null):void{
			dispatchEvent(new Event(StaticInfo.UPARROW_CLICK));
		}
		private function sendDownDispatch(e:TimerEvent=null):void{
			dispatchEvent(new Event(StaticInfo.DOWNARROW_CLICK));
		}
		public function delArrow():void {
			delEvent();
			stopMove();
			parent.removeChild(this);
		}

	}
}